#include<bits/stdc++.h>
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;

const int N=510;
char a[N][N];
queue<PII>q;
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool st[N][N];
int n,m;
int dis[N][N];
bool check(int x,int y){
	return x>=1&&x<=n&&y>=1&&y<=m;
}

int main(){
	
	while(cin>>n>>m){
		memset(dis,-1,sizeof dis);
		int x,y,xx,yy;
		for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
			cin>>a[i][j];
			if(a[i][j]=='S'){
				x=i,y=j;
			}
			if(a[i][j]=='E'){
				xx=i,yy=j;
			}
		}
	}
		q.push({x,y});
		dis[x][y]=0;
		while(q.size()){
			int x=q.front().fi;
			int y=q.front().se;
			q.pop();
			for(int i=0;i<4;++i){
				int dx=x+dir[i][0];
				int dy=y+dir[i][1];
				//cout<<dx<<" "<<dy<<endl;
				if( check(dx,dy) && (a[dx][dy]=='.'||a[dx][dy]=='E') && dis[dx][dx]==-1){
				//	cout<<dx<<" "<<dy<<endl;
					dis[dx][dy]=dis[x][y]+1;
					st[dx][dy]=true;
					q.push({dx,dy});
				}
			} 
		//	return 0;
		}
		if(dis[xx][yy])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
				cout<<dis[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}
